package com.example.administrator.yuejian23.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian23.Activity.MyShaiTuActivity;
import com.example.administrator.yuejian23.Bean.MyShaitu;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.Fragment.viewholder.UserShaituViewHolder;
import com.example.administrator.yuejian23.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/10/19.
 */

public class UserShaituAdapter extends RecyclerView.Adapter {


    private List<MyShaitu> userShaituList;
    private Context context;
    private LayoutInflater layoutInflater;
    private String name,pic;

    public UserShaituAdapter(Context context,List<MyShaitu> userShaituList,String name,String pic){
        this.context=context;
        this.userShaituList=userShaituList;
        this.name=name;
        this.pic=pic;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.item_user_shaitu,viewGroup,false);
        UserShaituViewHolder holder=new UserShaituViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        UserShaituViewHolder userShaiTuViewHolder= (UserShaituViewHolder) viewHolder;
        MyShaitu shaitu=userShaituList.get(position);
        String title=shaitu.getTitle();
        String time=shaitu.getUpdate_time();
        String photo= Const.PIC_URL+shaitu.getThumb0();
        String photo1= Const.PIC_URL+shaitu.getThumb1();
        String photo2= Const.PIC_URL+shaitu.getThumb2();
        userShaiTuViewHolder.u_title.setText(title);
        userShaiTuViewHolder.u_time.setText(time);
        userShaiTuViewHolder.u_name.setText(name);
        Picasso.with(context).load(pic).into(userShaiTuViewHolder.u_pic);
        if (!shaitu.getThumb0().equals("")){
            Picasso.with(context).load(photo).into(userShaiTuViewHolder.u_shaitu);
        }
        if (!shaitu.getThumb1().equals("")) {
            Picasso.with(context).load(photo1).into(userShaiTuViewHolder.u_shaitu1);
        }else {
            Picasso.with(context).load(R.mipmap.ic_myphoto).into(userShaiTuViewHolder.u_shaitu1);
        }
        if (!shaitu.getThumb2().equals("")) {
            Picasso.with(context).load(photo2).into(userShaiTuViewHolder.u_shaitu2);
        }else {
            Picasso.with(context).load(R.mipmap.ic_myphoto).into(userShaiTuViewHolder.u_shaitu2);
        }

    }

    @Override
    public int getItemCount() {
        return userShaituList.size();
    }



}
